define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/points/index',
                    table: 'points',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'total_score',
                sortOrder: 'desc',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.code', title: __('编号')},
                        {field: 'user.username', title: __('User.username')},
                        {field: 'total_score', title: __('Total_score')},
                        {field: 'sort', title: __('奖励'),formatter:function(index,item){
                            if(item.sort<=10){
                                return '水公园日场入园一次';
                            }else if(item.sort > 10 && item.sort <= 30 ){
                                return '水公园夜场入园一次';
                            }else if(item.sort > 30 && item.sort <= 70){
                                return '精美礼品一份（园区自取）';
                            }else{
                                return '未获得奖励';
                            }
                        }},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {
                            field: 'operate', 
                            title: __('Operate'),
                            buttons: [
                                {
                                    name: 'execute',
                                    title: __('详细记录'),
                                    text: __('详细记录'),
                                    url: 'user/points/detail/userid/{user_id}',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-execute btn-dialog'
                                }
                            ],
                        table: table, 
                        events: Table.api.events.operate, 
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});